package com.itbour.service.trade.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.trade.ItemsDao;
import com.itbour.dao.trade.PrintParaDao;
import com.itbour.dto.com.SizeInfoDto;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.trade.ItemInfoDto;
import com.itbour.dto.trade.PrintParaInfoDto;
import com.itbour.service.trade.ItemsService;
import com.itbour.service.trade.PrintParaService;
import com.opensymphony.xwork2.ActionContext;


/**
* 分页映射
* 
* copyright   itbour team 2016
* @author     abby
*
*/

public class PrintParaServiceImpl implements PrintParaService {

	private  PrintParaDao printParaDao;
	
	/**
	 * @param countKey
	 *            查询该表所有记录行的SQL语句ID
	 * @param sqlKey
	 *            需要查询记录的SQL语句ID
	 * @param param
	 *            传递给查询语句的参数
	 * @param pageNo
	 *            需要查询的实际页
	 * @param pageSize
	 *            每页记录行数
	 * @return page对象
	 */
	public Page printParaPgQuery(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = printParaDao.selectPrintParaCnt(param);
			
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<PrintParaInfoDto> data = printParaDao.selectPrintParaInfo(param);

			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}

	public List<PrintParaInfoDto> selectPrintParaInfo(Map<String,Object> param) {
		return printParaDao.selectPrintParaInfo(param);
	}
	
	public void delPrintPara(String delIds) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(delIds)));
		printParaDao.deletePrintParaInfoLogic(param);
	}

	public void addPrintPara(PrintParaInfoDto printParaInfo) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("pp_name", printParaInfo.getPp_name());
		param.put("desc", printParaInfo.getDesc());
		param.put("size_id", printParaInfo.getSize_id());
		param.put("type", printParaInfo.getType());
		param.put("state", printParaInfo.getState());
		param.put("name", printParaInfo.getName());
		param.put("style", printParaInfo.getStyle());
		param.put("mat", printParaInfo.getMat());
		param.put("tech", printParaInfo.getTech());
		param.put("thumbs", printParaInfo.getThumbs());
		param.put("pricing", printParaInfo.getPricing());
		
		param.put("update_by", printParaInfo.getUpdate_by());
		printParaDao.insertPrintParaInfo(param);
	}
	
	public void updPrintPara(Map<String,Object> param) {
		printParaDao.updatePrintParaInfoById(param);
	}
	
	public List<SizeInfoDto> selectSizeInfo(){
		return printParaDao.selectSizeInfo();
	}
	
	public PrintParaDao getPrintParaDao() {
		return printParaDao;
	}

	public void setPrintParaDao(PrintParaDao printParaDao) {
		this.printParaDao = printParaDao;
	}

}

